<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java 三剑客：final、finally、finalize 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        
        .keyword {
            color: #569cd6;
            font-weight: bold;
        }
        
        .comment {
            color: #6a9955;
        }
        
        .string {
            color: #ce9178;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .badge {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            padding: 0.25rem 1rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            font-weight: 500;
            display: inline-block;
            margin-bottom: 1rem;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                Java 三剑客
            </h1>
            <p class="text-2xl md:text-3xl mb-4 opacity-90">
                final、finally、finalize 深度解析
            </p>
            <p class="text-lg opacity-80 max-w-3xl mx-auto">
                探索 Java 中三个相似却截然不同的关键概念，掌握它们的本质区别与最佳实践
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Java 编程世界中，<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">final</code>、<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">finally</code>、<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">finalize</code> 是三个含义和用途截然不同的关键字或方法。虽然它们的名字相似，但在编程中的作用各有千秋。让我们深入探索这三个概念的奥秘。
            </p>
        </div>

        <!-- Concept Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center text-gray-800">概念关系图</h2>
            <div class="mermaid">
                graph TD
                    A[Java 三剑客] --> B[final 关键字]
                    A --> C[finally 块]
                    A --> D[finalize 方法]
                    
                    B --> B1[修饰类]
                    B --> B2[修饰方法]
                    B --> B3[修饰变量]
                    
                    C --> C1[异常处理]
                    C --> C2[资源释放]
                    C --> C3[必定执行]
                    
                    D --> D1[垃圾回收]
                    D --> D2[已过时]
                    D --> D3[Cleaner替代]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#4299e1,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#ed8936,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Three Cards Section -->
        <div class="grid md:grid-cols-3 gap-8 mb-12">
            <!-- final Card -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-lock"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">final 关键字</h3>
                <div class="badge mb-4">不可变性保证</div>
                <p class="text-gray-600 mb-6">
                    用于声明类、方法和变量，防止更改，保证程序的稳定性和安全性。
                </p>
                <ul class="space-y-3 text-gray-700">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <span><strong>修饰类：</strong>类不能被继承</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <span><strong>修饰方法：</strong>方法不能被重写</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <span><strong>修饰变量：</strong>变量值不能改变</span>
                    </li>
                </ul>
            </div>

            <!-- finally Card -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">finally 块</h3>
                <div class="badge mb-4">异常处理守护者</div>
                <p class="text-gray-600 mb-6">
                    与 try-catch 配合使用，无论是否抛出异常都会执行的代码块。
                </p>
                <ul class="space-y-3 text-gray-700">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-3"></i>
                        <span><strong>资源释放：</strong>确保资源正确关闭</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-3"></i>
                        <span><strong>必定执行：</strong>即使有 return 也会执行</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-3"></i>
                        <span><strong>清理操作：</strong>执行必要的清理工作</span>
                    </li>
                </ul>
            </div>

            <!-- finalize Card -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-trash-alt"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">finalize 方法</h3>
                <div class="badge mb-4">已过时的清理器</div>
                <p class="text-gray-600 mb-6">
                    Object 类的方法，用于垃圾回收前的清理，但已不推荐使用。
                </p>
                <ul class="space-y-3 text-gray-700">
                    <li class="flex items-start">
                        <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                        <span><strong>不可预测：</strong>调用时间不确定</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                        <span><strong>性能问题：</strong>可能导致性能下降</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-info-circle text-yellow-500 mt-1 mr-3"></i>
                        <span><strong>替代方案：</strong>Java 9+ 使用 Cleaner</span>
                    </li>
                </ul>
            </div>
        </div>

        <div class="section-divider"></div>

        <!-- Detailed Sections -->
        <!-- final Section -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-lock text-purple-600 mr-4"></i>
                    深入理解 final 关键字
                </h2>
                
                <div class="space-y-8">
                    <!-- final 类 -->
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-700">
                            <i class="fas fa-cube text-green-500 mr-2"></i>
                            final 修饰类
                        </h3>
                        <p class="text-gray-600 mb-4">
                            当一个类被声明为 final 时，这个类不能被继承。这种设计通常用于创建不可变类或确保类的行为不被改变。
                        </p>
                        <div class="code-block">
                            <pre><code><span class="keyword">public final class</span> MyClass {
    <span class="comment">// 该类不能被继承</span>
    <span class="comment">// String、Integer 等包装类都是 final 类</span>
}</code></pre>
                        </div>
                    </div>

                    <!-- final 方法 -->
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-700">
                            <i class="fas fa-code text-blue-500 mr-2"></i>
                            final 修饰方法
                        </h3>
                        <p class="text-gray-600 mb-4">
                            final 方法不能被子类重写，这确保了方法的行为在继承体系中保持一致。
                        </p>
                        <div class="code-block">
                            <pre><code><span class="keyword">public class</span> MyClass {
    <span class="keyword">public final void</span> myMethod() {
        <span class="comment">// 该方法不能被子类重写</span>
        <span class="comment">// 保证核心逻辑不被修改</span>
    }
}</code></pre>
                        </div>
                    </div>

                    <!-- final 变量 -->
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-gray-700">
                            <i class="fas fa-database text-purple-500 mr-2"></i>
                            final 修饰变量
                        </h3>
                        <p class="text-gray-600 mb-4">
                            final 变量一旦初始化后就不能再改变其值，常用于定义常量。
                        </p>